<template>
  <div>
    <el-row style="margin-top: 200px">
      <el-col :span="8">
        <div class="grid-content bg-purple">&nbsp;</div>
      </el-col>
      <el-col :span="8">
        <div class="grid-content bg-purple-light">
          <el-card class="box-card">
            <el-form :model="query" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
              <el-form-item label="用户名" prop="userName">
                <el-input v-model="query.userName"></el-input>
              </el-form-item>
              <el-form-item label="密码" prop="userPassword">
                <el-input v-model="query.userPassword" show-password></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="login()">登录</el-button>
              </el-form-item>
            </el-form>
          </el-card>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="grid-content bg-purple"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      query: {
        userName: 'admin',
        userPassword: '123456',
      },
      rules: {
        userName: [
          {required: true, message: '请输入用户名', trigger: 'blur'}
        ],
        userPassword: [
          {required: true, message: '请输入密码', trigger: 'blur'}
        ],
      },
    };
  },
  methods: {
    login() {
        this.axios.post('user/login', this.query).then((res) => {
        if (res.data.code == 200) {
          localStorage.setItem("token", res.data.data.token);
          localStorage.setItem("user", JSON.stringify(res.data.data.user));
          this.$message.success(res.data.msg);
          this.$router.push("index");
        } else {
          this.$message.error(res.data.msg);
        }
      })
    },
  },
  created() {

  }
}
</script>

<style>

</style>


